package com.zsh.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author zsh
 * @Description
 * @create 2022-01-24 17:09
 */

@Controller
public class UserController {

    /**
     * 使用Restful风格 模拟用户资源的增删改查
     * /user    get     查询所有
     * /user/1  get     根据Id查询单个
     * /user    Post    添加用户
     * /user/1  delete  根据id删除单个
     * /user/1  put     根据id修改单个
     */

    @RequestMapping(value = "/user",method = RequestMethod.GET)
    public String getAllUser(){
        System.out.println("查询所有用户");
        return "success";
    }

    @RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
    public String getUserById(@PathVariable("id") String id){
        System.out.println("根据Id查询单个" + id);
        return "success";
    }

    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public String addUser(String username,String password){
        System.out.println("添加用户" + username + ":" + password);
        return "success";
    }

    @RequestMapping(value = "/user/{id}",method = RequestMethod.PUT)
    public String updateUser(@PathVariable("id") String id,String username,String password){
        System.out.println("修改用户"+ id + "-" + username + ":" + password);
        return "success";
    }

    @RequestMapping(value = "/user/{id}",method = RequestMethod.DELETE)
    public String deleteUser(@PathVariable("id") String id){
        System.out.println("删除用户"+ id );
        return "success";
    }


}
